<?php

namespace Home\Model\Ajax;

class UserLoginVerify extends AbstractAjax
{
    public function handle()
    {
        $u        = D('User');
        $username = I('request.username', '', 'trim');
        $password = I('request.password', '', 'trim');
        $auto     = I('request.auto', '', 'trim');
        if (empty($username) || empty($password)) {
            $ajax['status']  = 0;
            $ajax['content'] = '用户名和密码不能为空';
            return $ajax;
        } else {
            $user = $u->verify_username_password($username, $password);
            if ($user) {
                $u->user_login($user);
                if ($auto == '1') {//设置cookie
                    cookie('ytata_username', $user['username'], 31536000);
                    cookie('ytata_password', $user['password'], 31536000);
                }
                $ajax['status']  = 1;
                $ajax['content'] = '登录成功！';
                return $ajax;
            } else {
                $ajax['status']  = 0;
                $ajax['content'] = '用户名或密码错误！尝试<span class="tip J_select_code">手机动态码</span>登录';
                return $ajax;
            }
        }
    }
}